#ifndef __REQUEST_H__
#define __REQUEST_H__

#define HTTP_AGAIN -2
#define HTTP_ERR -1
#define HTTP_OK 0

#define LF     (u_char) 10
#define CR     (u_char) 13
#define CRLF   "\x0d\x0a"

#define HTTP_TOO_LARGE_HEADER -2

#define METHOD_GET 1
#define METHOD_POST 2
#define METHOD_HEAD 3

typedef int (*location_handler_pt)(struct Conn *conn);

typedef struct location_handler {
    u_char *location;
    location_handler_pt handler;
}location_handler;

typedef struct Request {
    Conn *conn;
    
    Buf *header_in;
    
    String request_line;
    String uri;
    String method_name;
    String args;
    int http_version;
    int method;
    
    int state;

    //int header_hash;
    //int lowcase_index;
    //u_char  lowcase_header[32];

    ds_array_s *headers_in;

    u_char  *header_name_start;
    u_char  *header_name_end;
    u_char  *header_start;
    u_char  *header_end;
    
    u_char  *uri_start;
    u_char  *uri_end;
    u_char  *uri_ext;
    u_char  *args_start;
    u_char  *request_start;
    u_char  *request_end;
    u_char  *method_end;
    unsigned    http_minor:16;
    unsigned    http_major:16;

    
    unsigned    invalid_header:1;    
}Request;

int REQ_CreateRequest(Conn *conn);
void REQ_ProcessRequestLine(Event *rev);
void REQ_WriteClientBuf(Event *event);
int FinalizeConn(Conn *conn);

#endif

